/**
 * @Project : algorithm-learning
 * @Author : Ruoyu Wang
 * @User : Momenta
 * @DateTime : 2024/4/15 14:12
 */

#include <iostream>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

struct node {
    int a;
    int b;

    node(int a, int b) : a(a), b(b) {}

    bool operator==(const node &x) const {
        return a == x.a && b == x.b;
    }

    bool operator<(const node &x) const {
        return a == x.a ? b < x.b : a < x.a;
    }
};

struct nodehash {
    size_t operator()(const node &t) const {
        return t.a * 100 + t.b;
    }
};

int main() {
    node x = {1, 2};
    node y = {1, 2};
    node z = {2, 3};

    /**
     * unordered_set 存放自定义结构体
     */
    unordered_set<node, nodehash> set1;
    set1.insert(x);
    set1.insert(y);
    set1.insert(z);
    for (auto e: set1) {
        cout << e.a << " " << e.b << endl;
    }
    cout << endl;

    /**
    * unordered_map 存放自定义结构体
    */
    unordered_map<node, int, nodehash> map1;
    map1[x] = 1;
    map1[y] = 2;
    map1[z] = 3;
    for (auto e: map1) {
        cout << e.first.a << " " << e.first.b << " " << e.second << endl;
    }
    cout << endl;

    /**
    * set 存放自定义结构体
    */
    set<node> set2;
    set2.insert(x);
    set2.insert(y);
    set2.insert(z);
    for (auto e: set2) {
        cout << e.a << " " << e.b << endl;
    }
    cout << endl;

    /**
    * map 存放自定义结构体
    */
    map<node, int> map2;
    map2[x] = 1;
    map2[y] = 2;
    map2[z] = 3;
    for (auto e: map2) {
        cout << e.first.a << " " << e.first.b << " " << e.second << endl;
    }
    cout << endl;

    /**
    * priority_queue 存放自定义结构体
    */
    priority_queue<node> pq;
    pq.push(x);
    pq.push(y);
    pq.push(z);
    while (!pq.empty()) {
        cout << pq.top().a << " " << pq.top().b << endl;
        pq.pop();
    }
    cout << endl;

    /**
    * vector 存放自定义结构体
    */
    vector<node> vec;
    vec.push_back(x);
    vec.push_back(z);
    vec.push_back(y);
    sort(vec.begin(), vec.end());
    for (auto e: vec) {
        cout << e.a << " " << e.b << endl;
    }
    cout << endl;
    return 0;
}